<!--
 * @Author: panghu chenjh@datamargin.com
 * @Date: 2024-05-04 17:14:37
 * @LastEditors: panghu chenjh@datamargin.com
 * @LastEditTime: 2024-05-04 17:40:51
 * @FilePath: \zheye\src\components\Modal.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
<teleport to="#modal">
  <div class="modal d-block" v-if="visible">
    <div class="modal-dialog">
      <div class="modal-content">
        <div class="modal-header d-flex justify-content-between">
          <h5 class="modal-title">{{title}}</h5>
          <button type="button" class="close" data-dismiss="modal" aria-label="Close">
            <span aria-hidden="true" @click="onClose">&times;</span>
          </button>
        </div>
        <div class="modal-body">
          <slot></slot>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-secondary" data-dismiss="modal"  @click="onClose">取消</button>
          <button type="button" class="btn btn-primary"  @click="onConfirm">确定</button>
        </div>
      </div>
    </div>
  </div>
</teleport>
</template>

<script lang="ts">
import { defineComponent, watch } from 'vue'
import useDomCreate from '@/hooks/useDomCreate'
export default defineComponent({
  name: 'ModalUI',
  props: {
    title: String,
    visible: {
      type: Boolean,
      default: false
    }
  },
  emits: ['modal-on-close', 'modal-on-confirm'],
  setup (props, context) {
    useDomCreate('modal')
    const onClose = () => {
      context.emit('modal-on-close')
    }
    const onConfirm = () => {
      context.emit('modal-on-confirm')
    }
    return {
      onClose,
      onConfirm
    }
  }
})
</script>
